export const numIpt = /^[0-9]*$/
export const money = /^\d+(\.\d+)?$/
export const moneys = /^((\d{1,3}(,\d{0,3})+?|\d+)(\.\d{1,2})?|(\.\d{1,2}))$/
export const identity = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
export const phone = /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8])|(19[7]))\d{8}$/
// 校验开始时间和结束时间是否为空
export const startTimeVerify = /\S/
// 校验长度是否20位
export const digitVerify = /^[\S]{0,20}$/

export  function validateIdCard (code){ // 校验二代居民身份证
  if(/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2]\d)|(3[0-1]))((\d{4})|(\d{3}[Xx]))$/.test(code)==false){
    return false;
  }
  code = code.split('');
  var factor = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
  var parity = [1,0,'X',9,8,7,6,5,4,3,2];
  var sum = 0;
  var ai = 0;
  var wi = 0;
  for(var i=0;i<17;i++){
    ai = code[i];
    wi = factor[i];
    sum+=ai*wi;
  }

  var last = parity[sum%11];
  if(parity[sum%11]!=code[17]){
    return false;
  }
  return true;
}

export default {
  phone:[{
    required: true,
    whitespace: true,
    validator:(obj,val,callback)=>{
      (val == undefined || val==='') ?  callback('手机号不能为空') 
      : (val.length!==11)?callback('请输入11位的手机号')
      :(new RegExp(phone) ?  callback()  :callback('请输入正确的手机号') )
    }
  }],
  idCard:[{
    required: true,
    validator:(obj,val,callback)=>{
      validateIdCard(val) ? callback() : callback('身份证号码输入格式有误')
    }
  }],


}
